package MtG.server.components;

import java.io.File;
import java.io.IOException;
import java.util.logging.FileHandler;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.logging.SimpleFormatter;

/**
 * ErrorLogger.java is the class that is used for logging 
 * the errors the game server might encounter. 
 * where all the cards in play will be situated.
 * @author Marek Sirp
 * @author Jaan Sepp
 */
public class ErrorLogger {
	
	/**
	 * Location where the log will be stored.
	 */
	File dir = new File (".\\Logs");
	/**
	 * Name of the logger.
	 */
	private final String LOGGERNAME = "MyLog";
	
	/**
	 * 
	 */
	private final String logName = "log";
			
	/**
	 * 
	 */
	public ErrorLogger(){
		if(!dir.exists()){
			dir.mkdir();
		}
	}
	

	  
	/**
	 * log function
	 * @param log - message
	 * @param level - message level
	 */
	public void login(String log, Level level) {
		try {
			Logger logger = Logger.getLogger(LOGGERNAME);
	    	FileHandler filehandler = new FileHandler(dir.getCanonicalPath() + System.getProperty("file.separator") + logName, true);
	    	filehandler.setFormatter(new SimpleFormatter());
	    	logger.addHandler(filehandler);
	    	logger.log(level, log);	 
	    	filehandler.flush();
	    	filehandler.close();
	    } catch (IOException ioe) {
	    	ioe.printStackTrace();
	    }
	}
	
}